package indi.dbfmp.oio.oauth.core.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import indi.dbfmp.oio.oauth.core.innerService.ISystemInnerService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import indi.dbfmp.oio.oauth.core.entity.System;

import java.util.List;

/**
 * <p>
 *  系统服务
 * </p>
 *
 * @author dbfmp
 * @name: SystemService
 * @since 2020/12/2 下午10:12
 */
@RequiredArgsConstructor
@Slf4j
@Service
public class SystemService {

    private final ISystemInnerService systemInnerService;

    public System getSysConfigByKey(String configKey) {
        return systemInnerService.getOne(new LambdaQueryWrapper<System>().eq(System::getConfigKey,configKey));
    }

    public List<System> getSysConfigListByKey(String configKey) {
        return systemInnerService.list(new LambdaQueryWrapper<System>().eq(System::getConfigKey,configKey));
    }

    public boolean addNewSysConfig(System system) {
        return systemInnerService.saveOrUpdate(system,new LambdaQueryWrapper<System>().eq(StrUtil.isNotBlank(system.getId()), System::getId,system.getId()));
    }

    public boolean delSysConfig(String systemConfigKey) {
        return systemInnerService.removeById(systemConfigKey);
    }

}
